<?php
namespace Doctrine\Common\Cache;

/**
 * Memcache cache driver.
 *
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @link    www.doctrine-project.org
 * @since   2.0
 * @version $Revision: 3938 $
 * @author  Benjamin Eberlei <kontakt@beberlei.de>
 * @author  Guilherme Blanco <guilhermeblanco@hotmail.com>
 * @author  Jonathan Wage <jonwage@gmail.com>
 * @author  Roman Borschel <roman@code-factory.org>
 * @author  David Abdemoulaie <dave@hobodave.com>
 */
class ZendCache extends AbstractCache
{

    /**
     * @var Zend_Cache_Core
     */
    private $_cache;
    /**
     * Sets the cache instance to use.
     *
     * @param \Zend_Cache_Core $memcache
     */
    public function setCache(\Zend_Cache_Core $cache)
    {
        $this->_cache = $cache;
    }

    /**
     * Gets the cache instance used by the cache.
     *
     * @return \Zend_Cache_Core
     */
    public function getCache()
    {
        return $this->_cache;
    }

    /**
     * {@inheritdoc}
     */
    public function getIds()
    {
        return $this->_cache->getIds();
    }

    /**
     * {@inheritdoc}
     */
    protected function _doFetch($id)
    {
        return $this->_cache->load($id);
    }

    /**
     * {@inheritdoc}
     */
    protected function _doContains($id)
    {
        return (bool) $this->_cache->test($id);
    }

    /**
     * {@inheritdoc}
     */
    protected function _doSave($id, $data, $lifeTime = 0)
    {
        return $this->_cache->save($data, $id, array(), (int) $lifeTime);
    }

    /**
     * {@inheritdoc}
     */
    protected function _doDelete($id)
    {
        return $this->_cache->remove($id);
    }
}
